//递归版
function deepFn(n) {
  if (n <= 2) {
    return 1;
  }

  return deepFn(n - 1) + deepFn(n - 2);
}

// 循环版

function ForFn(n) {
  let arr = [1, 1];
  for (let i = 2; i < n; i++) {
    arr.push(arr[i - 1] + arr[i - 2]);
  }
  return arr[n - 1];
}

function ForFn1(n) {
  let pre = 1,
    next = 1,
    result;
  if (n <= 2) return pre;
  for (let i = 2; i < n; i++) {
    result = pre + next;
    pre = next;
    next = result;
  }
  return result;
}

console.log(ForFn(20));
// console.log(deepFn(50));
console.log(ForFn1(20));
